package br.com.abril.booking.transformer;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import br.com.abril.booking.ExecutiveBooking;
import br.com.abril.prevision.ExecutivePrevision;

import com.force.abril.api.maintanence.client.request.MaintenanceAdvertiseInfo;
import com.force.abril.api.maintanence.client.request.MaintenanceExecutiveInfo;
import com.force.abril.api.maintanence.client.request.MaintenanceInfo;
import com.force.abril.api.maintanence.client.request.MaintenanceProductInfo;
import com.force.abril.api.maintanence.client.request.MaintenanceEntry;


@Component
public class BookingMaintenanceTransformer {
	


	public MaintenanceEntry toMaintenance( List<ExecutiveBooking> executives  ) {
		
		MaintenanceEntry request = new MaintenanceEntry();
		request.setMaintenance( toMaintenanceInfo( executives.get(0)) );
		request.getAdvertisers().add( toAdvertiseInfo(executives.get(0)) );
		request.getProducts().add(toMaintenanceProductInfo(executives.get(0)));
		request.setExecutives( toMaintenanceExecutiveInfo(executives));
		
		return request;
	}

	public MaintenanceInfo toMaintenanceInfo ( ExecutiveBooking executive  ) {
		MaintenanceInfo maintenance = new MaintenanceInfo();
		maintenance.setAdvertiserOfficeFilter( executive.getOfficeIdInt()  + "." + executive.getAdvertiserIdInt() );
		maintenance.setProductFilter(executive.getProductIdInt());
		return maintenance;
	}
	
	
	public List<MaintenanceExecutiveInfo> toMaintenanceExecutiveInfo ( List<ExecutiveBooking> executives) {
		List<MaintenanceExecutiveInfo> maintenances = new ArrayList<MaintenanceExecutiveInfo>();
		for (ExecutiveBooking executiveBooking : executives) {
			maintenances.add( toMaintenanceExecutiveInfo(executiveBooking) );
		}
		return maintenances;
	}
	
	public MaintenanceExecutiveInfo toMaintenanceExecutiveInfo(ExecutiveBooking executive) {
		MaintenanceExecutiveInfo executiveInfo = new MaintenanceExecutiveInfo();
		executiveInfo.setApportionment( Double.valueOf( executive.getPorcentagemAtendimento__c()  )  );
		executiveInfo.setPercentage( Double.valueOf( executive.getPercentualRateio__c() ) );
		executiveInfo.setPrimeExecutive(Boolean.valueOf( executive.getPrincipalExecutivo__c() ));
		executiveInfo.setExecutive(  executive.getExecutivoMigrado__c() );
		
		return executiveInfo;
	}
	
	public List<MaintenanceAdvertiseInfo> toAdvertiseInfo ( List<ExecutiveBooking> executives) {
		List<MaintenanceAdvertiseInfo> maintenances = new ArrayList<MaintenanceAdvertiseInfo>();
		for (ExecutiveBooking executiveBooking : executives) {
			maintenances.add( toAdvertiseInfo(executiveBooking) );
		}
		return maintenances;
	}
	
	public MaintenanceAdvertiseInfo toAdvertiseInfo (ExecutiveBooking executive) {
		MaintenanceAdvertiseInfo advertiseInfo = new MaintenanceAdvertiseInfo();
		
		advertiseInfo.setAdvertise(executive.getAdvertiser());
		advertiseInfo.setOffice(executive.getOffice());
		advertiseInfo.setSearchKey(executive.getOfficeIdInt()  + "." + executive.getAdvertiserIdInt() );
		
		return advertiseInfo;
	}
	
	public List<MaintenanceProductInfo> toMaintenanceProductInfo ( List<ExecutiveBooking> executives) {
		List<MaintenanceProductInfo> maintenances = new ArrayList<MaintenanceProductInfo>();
		for (ExecutiveBooking executiveBooking : executives) {
			maintenances.add( toMaintenanceProductInfo(executiveBooking) );
		}
		return maintenances;
	}
	
	
	public MaintenanceProductInfo toMaintenanceProductInfo(ExecutiveBooking executive) {
		
		MaintenanceProductInfo maintenanceProductInfo = new MaintenanceProductInfo();
		maintenanceProductInfo.setProduct(executive.getProduct());
		maintenanceProductInfo.setUn(executive.getUn());
		maintenanceProductInfo.setProductGroup(executive.getProductGroup());
		return maintenanceProductInfo;

	}
	
	public MaintenanceEntry toMaintenancePrevision( List<ExecutivePrevision> executives  ) {
		
		MaintenanceEntry request = new MaintenanceEntry();
		request.setMaintenance( toMaintenanceInfo( executives.get(0)) );
		request.getAdvertisers().add( toAdvertiseInfo(executives.get(0)) );
		request.getProducts().add(toMaintenanceProductInfo(executives.get(0)));
		request.setExecutives( toMaintenanceExecutivePrevisionInfo(executives));
		
		return request;
	}

	public MaintenanceInfo toMaintenanceInfo ( ExecutivePrevision executive  ) {
		MaintenanceInfo maintenance = new MaintenanceInfo();
		maintenance.setAdvertiserOfficeFilter( executive.getOfficeIdInt()  + "." + executive.getAdvertiserIdInt() );
		maintenance.setProductFilter(executive.getProductIdInt());
		return maintenance; 
	}	
	
	public List<MaintenanceExecutiveInfo> toMaintenanceExecutivePrevisionInfo(List<ExecutivePrevision> executives) {
		
		List<MaintenanceExecutiveInfo> maintenances = new ArrayList<MaintenanceExecutiveInfo>();
		for (ExecutivePrevision executive : executives) {
			maintenances.add( toMaintenanceExecutiveInfo(executive) );
		}
		return maintenances;
		
	}
	
	public MaintenanceExecutiveInfo toMaintenanceExecutiveInfo(ExecutivePrevision executive) {
		MaintenanceExecutiveInfo executiveInfo = new MaintenanceExecutiveInfo();
		
		executiveInfo.setApportionment(Double.valueOf( executive.getPercentualAtendimento__c() ));
		executiveInfo.setPercentage(Double.valueOf( executive.getPercentualRateio__c() ));
		
		executiveInfo.setPrimeExecutive(Boolean.valueOf( executive.getPrincipalExecutivo__c() ));
		executiveInfo.setExecutive(  executive.getExecutivoMigrado__c() );
		
		return executiveInfo;
	}
	
	public MaintenanceAdvertiseInfo toAdvertiseInfo (ExecutivePrevision executive) {
		MaintenanceAdvertiseInfo advertiseInfo = new MaintenanceAdvertiseInfo();
		
		advertiseInfo.setAdvertise(executive.getAdvertiser());
		advertiseInfo.setOffice(executive.getOffice());
		advertiseInfo.setSearchKey(executive.getOfficeIdInt()  + "." + executive.getAdvertiserIdInt() );
		
		return advertiseInfo;
	}
	
	public MaintenanceProductInfo toMaintenanceProductInfo(ExecutivePrevision executive) {
		
		MaintenanceProductInfo maintenanceProductInfo = new MaintenanceProductInfo();
		maintenanceProductInfo.setProduct(executive.getProduct());
		maintenanceProductInfo.setUn(executive.getUn());
		maintenanceProductInfo.setProductGroup(executive.getProductGroup());
		return maintenanceProductInfo;

	}

}


